package com.eightbears.beboy.adapter;

import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.cache.DistrictCache;
import com.eightbears.beboy.base.util.CommonUtils;
import com.eightbears.beboy.entity.NeartyPeopleEntity;
import com.makeramen.roundedimageview.RoundedImageView;

/**
 * Created by Bao on 2016/12/7.
 */

public class NearbyPeopleAdapter extends BaseQuickAdapter<NeartyPeopleEntity.DataBean.ListBean, BaseViewHolder> {

    public NearbyPeopleAdapter() {
        super(R.layout.item_nearby_people, null);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void convert(BaseViewHolder baseViewHolder, NeartyPeopleEntity.DataBean.ListBean listBean) {
        CommonUtils.loadImageView(mContext, listBean.getCover(), R.mipmap.default_head,
                (RoundedImageView) baseViewHolder.getView(R.id.iv_user_head));
        baseViewHolder.setText(R.id.tv_name, listBean.getNickname())
                .setText(R.id.tv_city, DistrictCache.getInstance(mContext).getCacheById(String.valueOf(listBean.getDistrict_id())).getName())
                .addOnClickListener(R.id.iv_user_head)
                .addOnClickListener(R.id.add_friend);

        ImageView iv_sex = baseViewHolder.getView(R.id.iv_sex);
        if (listBean.getSex() == 1) {
            iv_sex.setImageDrawable(mContext.getDrawable(R.mipmap.icon_nearby_male));
            iv_sex.setVisibility(View.VISIBLE);
        } else if (listBean.getSex() == 2) {
            iv_sex.setImageDrawable(mContext.getDrawable(R.mipmap.icon_nearby_female));
            iv_sex.setVisibility(View.VISIBLE);
        }

        if (listBean.getVip_level() > 0) {
            baseViewHolder.getView(R.id.iv_vip).setVisibility(View.VISIBLE);
            if (listBean.getVip_level() == 1) {
                baseViewHolder.setImageResource(R.id.iv_vip,R.mipmap.icon_new_vip1 );
            } else if (listBean.getVip_level() == 2) {
                baseViewHolder.setImageResource(R.id.iv_vip,R.mipmap.icon_new_vip2 );
            }
        } else {
            baseViewHolder.getView(R.id.iv_vip).setVisibility(View.GONE);
        }
    }
}